﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
@* 种母历史记录添加 *@
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>

<body>

    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-form-item">

                <button type="button" class="layui-btn layui-bg-red" id="searchBtn" onclick="Show()">删除</button>

                <button type="button" class="layui-btn layui-bg-red" onclick="AddInput()" lay-on="test-iframe-curl">新增</button>
            </div>


        </div>
        <table class="layui-table" style="width: 150%;">
            <thead>
                <tr>
                    <td>种母耳号</td>
                    <td>配种日期</td>
                    <td>种公耳号</td>
                    <td>妊捡日期</td>
                    <td>分娩日期</td>
                    <td>健羔数</td>
                    <td>健羔总重</td>
                    <td>弱羔数</td>
                    <td>畸形数</td>
                    <td>死胎数</td>
                    <td>木乃伊数</td>
                    <td>畸胎数</td>
                    <td>当前胎次</td>
                    <td>断奶日期</td>
                    <td>断奶只数</td>
                    <td>断奶窝重</td>
                </tr>
            </thead>
            <tbody>
                <tr>
                    @* 种母耳号 *@
                    <td>
                        <select id="breedingEarBugle" lay-filter="testSelect">
                            <option value="">请选择</option>
                            <option value="656436356436">656436356436</option>
                            <option value="646565476766">646565476766</option>
                            <option value="655342324245">655342324245</option>
                        </select>
                    </td>
                    @* 配种日期 *@
                    <td> <input type="date" id="dateBreeding" class="layui-input"></td>
                    @* 种公耳号 *@
                    <td>
                        <select id="seedMaleEarBugle" lay-filter="testSelect">
                            <option value="">请选择</option>
                            <option value="676878787877">676878787877</option>
                            <option value="656434545566">656434545566</option>
                            <option value="658898976754">658898976754</option>
                        </select>
                    </td>
                    @* 妊捡日期 *@
                    <td> <input type="date" id="pregnancyTestDate" class="layui-input"></td>
                    @* 分娩日期 *@
                    <td> <input type="date" id="parturitionDate" class="layui-input"></td>
                    @* 健羔数 *@
                    <td> <input type="text" id="healthyLambNums" class="layui-input"></td>
                    @* 健羔总重 *@
                    <td> <input type="text" id="healthyLambWeight" class="layui-input"></td>
                    @* 弱羔数 *@
                    <td> <input type="text" id="weakLambsNums" class="layui-input"></td>
                    @* 畸形数 *@
                    <td> <input type="text" id="deformityNums" class="layui-input"></td>
                    @* 死胎数 *@
                    <td> <input type="text" id="stillbirthNums" class="layui-input"></td>
                    @* 木乃伊数 *@
                    <td> <input type="text" id="mummificationNums" class="layui-input"></td>
                    @* 畸胎数 *@
                    <td> <input type="text" id="teratogenesiNums" class="layui-input"></td>
                    @* 当前胎次 *@
                    <td> <input type="text" id="currentParity" class="layui-input"></td>
                    @* 断奶日期 *@
                    <td> <input type="date" id="weanedDate" class="layui-input"></td>
                    @* 断奶只数 *@
                    <td> <input type="text" id="weanedNums" class="layui-input"></td>
                    @* 断奶窝重 *@
                    <td> <input type="text" id="weanedLitterWeight" class="layui-input"></td>

                </tr>
            </tbody>
        </table>

    </form>


    <script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script>


</body>

</html>
<script>
    layui.use('form', function () {
        var table = layui.table;
        var form = layui.form;
        var layer = layui.layer;

        //绑定耳号
        bangsheng1();
        //绑定栋舍
        bangsheng();

        FantearBugles();



        //获取耳号下拉框的值
        form.on('select(testSelect)', function (data) {
            FantearBugles(data.value); // data.value 返回选中的值
            console.log(data.value, 6666666666)
        });


        //绑定栋舍
        function bangsheng() {
            $.ajax({
                url: "http://localhost:5123/api/Cottage/CottageSecondaryQuery",
                data: JSON.stringify({}),
                type: "post",
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    console.log(res)
                    $.each(res.data, function () {
                        $("#cottageId").append(`<option value="${this.cottageId}">${this.cottageName}</option>`);
                    })
                    form.render('select'); // 重新渲染下拉框
                }
            })
        }

        //获取栋舍下拉框的值
        form.on('select(provincet)', function (data) {
            provincetId1 = data.value;
            console.log(provincetId1, 15152)
            $("#field").empty();
            $("#field").append('<option value="">请选择</option>');
            bangshi()

        });

        //绑定栏位
        function bangshi() {
            var cottageId = $("#cottageId").val();
            $.ajax({
                url: "http://localhost:5123/api/Field/GetFieldCottage",
                data: JSON.stringify({ cottageId: cottageId }),
                type: "post",
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    console.log(res.data)

                    $.each(res.data, function () {
                        $("#field").append(`<option value="${this.fieldId}">${this.fieldName}</option>`);
                    })
                    form.render('select'); // 重新渲染下拉框
                }

            })
        }

        //绑定耳号
        function bangsheng1() {

            $.ajax({
                url: "http://localhost:5269/api/SheepArchive/SheepEarBuglesQuery",
                data: JSON.stringify({}),
                type: "post",
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    console.log(res)
                    $.each(res.data, function () {
                        $("#earBugles").append(`<option value="${this.recordAuricle}">${this.recordAuricle}</option>`);
                    })
                    form.render('select'); // 重新渲染下拉框

                }

            })
        }

        //根据耳号加载数据
        function FantearBugles(aa) {
            //var recordAuricle = $("#earBugles").val();
            $.ajax({
                url: 'http://localhost:5269/api/SheepArchive/SheepEarBuglesBackFill',
                type: 'post',
                data: JSON.stringify({ recordAuricle: aa }),
                dataType: 'json',
                contentType: 'application/json',
                success: res => {
                    $(res.data).each(function () {
                        $("#cottageName").val(this.cottageName)
                        $("#fieldName").val(this.fieldName)
                    })
                    console.log(res, 88888)
                }
            })
        }

    })


    //历史记录新增
    function AddInput() {
        var data = {
            breedingEarBugle: $("#breedingEarBugle").val(),
            dateBreeding: $("#dateBreeding").val(),
            seedMaleEarBugle: $("#seedMaleEarBugle").val(),
            pregnancyTestDate: $("#pregnancyTestDate").val(),
            parturitionDate: $("#parturitionDate").val(),
            healthyLambNums: $("#healthyLambNums").val(),
            healthyLambWeight: $("#healthyLambWeight").val(),
            weakLambsNums: $("#weakLambsNums").val(),
            deformityNums: $("#deformityNums").val(),
            stillbirthNums: $("#stillbirthNums").val(),
            mummificationNums: $("#mummificationNums").val(),
            teratogenesiNums: $("#teratogenesiNums").val(),
            currentParity: $("#currentParity").val(),
            weanedDate: $("#weanedDate").val(),
            weanedNums: $("#weanedNums").val(),
            weanedLitterWeight: $("#weanedLitterWeight").val(),

        }
        $.ajax({
            url: "http://localhost:5269/api/BreedingHistorys/BreHistorysCreate",
            type: "post",
            data: JSON.stringify(data),
            dataType: "json",
            contentType: "application/json",
            success: d => {
                if (d == 0) {
                    layer.msg('保存成功');
                    location.href = "/Birth/BreedingHistory/"
                }
                else {
                    layer.msg('保存成功');


                }
            }
        })



    }


</script>